package com.istudy.service.imp;

import com.istudy.dao.xyjdao.CommentIntDao;
import com.istudy.dao.xyjdao.impl.CommentImplDao;
import com.istudy.entity.Comment;
import com.istudy.entity.CommentsPage;
import com.istudy.utils.JDBCUtils;

import java.sql.SQLException;
import java.util.List;

/**
 * @author xdd
 * @create 2020-09-03 15:22
 */
public class XYJCommentPageImpService  {

    CommentIntDao commentimpl;//初始或评论列表数据持久层
    {
        commentimpl = new CommentImplDao(JDBCUtils.getConnection());
    }

    /**
     * 根据pageIndex(当前页索引)获取评论列表
     *
     * @param pageIndex
     * @return
     */
    public CommentsPage getCommentsPage(String pageIndex) {
        CommentsPage commentsPage = new CommentsPage();//评论分页对象

        try{
            int i = Integer.parseInt(pageIndex);
            commentsPage.setIndexPage(i);//设置当前页索引
        }catch(Exception e){
            System.out.println("当前页索引转换异常"+e.fillInStackTrace());
        }
        List<Comment> comments=null;//评论列表
        try {
            Integer indexPage = commentsPage.getIndexPage();//当前页索引
            int pageSize = commentsPage.getPageSize();//单页显示数量
            comments = commentimpl.selectCommentinformation(indexPage,pageSize);//获取评论列表
        } catch (SQLException e) {
            e.printStackTrace();
        }
        commentsPage.setCommentsList(comments);//set评论列表

        try {
            Integer commentCount = commentimpl.selectVideoCount();
            commentsPage.setCommentCount(commentCount);//set评论列表总记录数
        } catch (SQLException e) {
            e.printStackTrace();
        }

        System.out.println(commentsPage.getPageCount());
        return commentsPage;
    }

}
